package com.wzl.backend.controller;

import com.wzl.backend.common.Result;
import com.wzl.backend.pojo.Word;
import com.wzl.backend.service.DayRecitationTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/study")
@Api(tags = "英语学习接口")
@CrossOrigin("*")
public class StudyController {

    @Autowired
    DayRecitationTableService dayRecitationTableService;

    @PostMapping("study")
    @ApiOperation("当天学习完成接口")
    public Result studyToday(@ApiParam("用户id") Long uId ,
                             @ApiParam("单词id json数组格式!") String wordIdsJson) {
        dayRecitationTableService.studyToday(uId , wordIdsJson);
        return Result.ok();
    }

    @GetMapping("getTodayStudyWordCount")
    @ApiOperation("根据用户id查看今天学习了多少个单词")
    public Result getStudyWordCount(Long uId) {
        int count = dayRecitationTableService.getStudyWordCount(uId);
        return Result.ok(count);
    }

    @GetMapping("getAllStudyWordCount")
    @ApiOperation("根据用户id查看总共学习了多少个单词")
    public Result getAllStudyWordCount(Long uId) {
        int count = dayRecitationTableService.getAllStudyWordCount(uId);
        return Result.ok(count);
    }

    @GetMapping("learning")
    @ApiOperation("通过用户id获取今天需要背的单词")
    public Result learning(@ApiParam("用户id") Long uId,
                           @ApiParam("一次背多少个单词") int limit) {
        List<Word> words = dayRecitationTableService.learning(uId , limit);
        return Result.ok(words);
    }

    @GetMapping("getAllStudyDate")
    @ApiOperation("通过用户id获取所有的学习数据(每天背诵单词的数量)")
    public Result getAllStudyDate(Long id) {
        List<Map<String , Object>> list = dayRecitationTableService.getAllStudyDate(id);
        return Result.ok(list);
    }

}
